package com.tuling.core.plugin.logplugin;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 定义切面
 * 
 * @author lenovo
 *
 */
@Component
public class LogPrinterPlugin implements ApplicationContextAware {
	// 获取容器上下文，可以去取容器的任何东西
	private ApplicationContext ac;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		this.ac = applicationContext;
	}

	public LogPrinterPlugin() {
		System.out.println("==========LogPlugin 启动成功");
		// 获取所有标注了@Service的Bean
		Class<Service> annotionType = Service.class;
		// Alt+Shift+L ,快速生成返回值对象
		Map<String, Object> beansWithAnnotation = ac.getBeansWithAnnotation(annotionType);// 从容器里面取出所有加了对应注解的类
		Set<Entry<String, Object>> entrySet = beansWithAnnotation.entrySet();
		for (Entry<String, Object> entry : entrySet) {
			System.out.println(entry.getKey());
//			Object target = entry.getValue();
//			ProxyFactory proxyFactoryBean=new ProxyFactory();
//	        proxyFactoryBean.setTarget(target);//设置目标对象
//	        proxyFactoryBean.addAdvice(new BeforeAdvice());//为目标对象织入增强
 		}
	}
}
